package com.LostAndFound.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.LostAndFound.domain.User;
import com.LostAndFound.utils.DataSourceUtils;

public class UserRegisterDao {

	public int checkUsername(String username) throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select count(*) from user where username = ?";
		Long row = (Long) runner.query(sql, new ScalarHandler(),username);
		return row.intValue();
	}

	public void regeisterUser(User user) throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "insert into user values(?,?,?,?,?,?,?,?)";
		Object[] params = {user.getUid(),user.getUsername(),user.getPassword(),user.getGender(),user.getCellphone(),
				user.getEmail(),user.getRealname(),user.getResume()};
		runner.update(sql, params);
	}

}
